package com.dubbo.mapper;

import com.dubbo.domain.Address;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;
import java.util.Map;

/**
 * 收货地址
 * @author gujiahua
 * @date 2018年12月17日 下午5:02:40
 */
public interface AddressMapper extends Mapper<Address> {
    
	/**
	 * 收货地址列表
	 * @author gujiahua
	 * 2018年12月17日 下午5:13:20
	 * @param userId
	 * @param pageStart
	 * @param pageTotal
	 * @return
	 */
	@Select("SELECT " + 
			"	ad.id AS addressId, " + 
			"	ad.`name`, " + 
			"	ad.phone, " + 
			"	ad.telePhone, " + 
			"	ad.province, " + 
			"	ad.city, " + 
			"	ad.area, " + 
			"	ad.address, " + 
			"	ad.defaultAddress, " + 
			"	ad.zipcode, " + 
			"	ad.userId, " + 
			"	ad.create_time " + 
			"FROM " + 
			"	u_address ad " + 
			"WHERE " + 
			"	ad.userId = #{userId} " + 
			"ORDER BY ad.defaultAddress DESC,ad.create_time DESC " + 
			"LIMIT #{pageStart},#{pageTotal} ")
	List<Map<String,Object>> getAddressList(@Param("userId") String userId, @Param("pageStart") Long pageStart, @Param("pageTotal") Long pageTotal);
	
	/**
	 * 收货地址列表
	 * @author gujiahua
	 * 2018年12月17日 下午5:13:20
	 * @param userId
	 * @param pageStart
	 * @param pageTotal
	 * @return
	 */
	@Select("SELECT " + 
			"	COUNT(ad.id) " + 
			"FROM u_address ad " + 
			"WHERE ad.userId = #{userId}")
	Long getAddressListCount(@Param("userId") String userId);

	/**
	 * 获取修改地址详情
	 * @author wujunyuan
	 * @date 2018年12月28日  下午5:45:41
	 * @param addressId 修改地址原id
	 * @return
	 */
	@Select("SELECT " + 
			"	uas.userId, " + 
			"	uas.`name`, " + 
			"	uas.phone, " + 
			"	uas.province, " + 
			"	uas.city, " + 
			"	uas.area, " + 
			"	uas.address " + 
			"FROM " + 
			"	u_address uas " + 
			"WHERE " + 
			"	uas.id = #{addressId}")
	Map<String, Object> getUpdateDefaultAddress(@Param("addressId") String addressId);
}